<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('system_settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique()->comment('设置键名');
            $table->text('value')->nullable()->comment('设置值');
            $table->string('type')->default('string')->comment('数据类型：string,integer,boolean,json,text');
            $table->string('group')->default('general')->comment('设置分组');
            $table->string('label')->comment('设置标签');
            $table->text('description')->nullable()->comment('设置描述');
            $table->text('options')->nullable()->comment('选项配置(JSON格式)');
            $table->boolean('is_public')->default(false)->comment('是否公开(前端可访问)');
            $table->boolean('is_required')->default(false)->comment('是否必填');
            $table->integer('sort_order')->default(0)->comment('排序');
            $table->timestamps();
            
            // 添加索引
            $table->index(['group', 'sort_order']);
            $table->index('is_public');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('system_settings');
    }
};
